package org.gnome.wsgalaxy.gnodroid;

import android.content.Context;
import android.util.Log;

import org.json.JSONObject;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class Global {
    public static final int PORT = 10086;
    public static Context SERVICE_CONTEXT = null;

    public static byte[]
    JsonToByte(JSONObject jsonObject)
    {
        if (jsonObject == null) {
            return null;
        }

        try {
            byte[] jsonData = jsonObject.toString().getBytes("UTF-8");
            byte[] resData = new byte[jsonData.length + 4 + 1];
            ByteBuffer byteBuffer = ByteBuffer.wrap(resData);
            byteBuffer.order(ByteOrder.BIG_ENDIAN);
            byteBuffer.clear();
            byteBuffer.putInt(jsonData.length + 1);
            byteBuffer.put(jsonData);
            byteBuffer.put((byte) 0);
            return resData;
        } catch (Exception e) {
            Log.d("gnd", e.toString());
            e.printStackTrace();
            return null;
        }
    }

}
